//    Copyright (C) Kherty.  All rights reserved.
using System;

namespace OpenLS.Spreadsheet
{
    class StableSelectionScope: IDisposable
    {
        public StableSelectionScope(Worksheet worksheet)
        {
            this.worksheet = worksheet;
            if (worksheet.Selection != null)
                selection = worksheet.Selection.Address;
            if (worksheet.ActiveCell != null)
                activeCell = worksheet.ActiveCell.Address;
        }

        readonly Worksheet worksheet;
        readonly RangeAddress selection;
        readonly CellAddress activeCell;
        #region IDisposable Members

        public void Dispose()
        {
            worksheet.Selection = worksheet.GetRange(selection);
            worksheet.ActiveCell = worksheet[activeCell];
        }

        #endregion
    }
}
